var searchDay="";
var sellerCode="";
$(document).ready(function() {
	//top.UppTabs.operator = top.getCurrentTagTitle();// 设置用户tab的标题值

	$('#tt').tree({
		url : contextPath + '/iccard/report/getDateTree',
		onClick : function(node) {
			list(node.id);
		}
	});
	$( "#sellers" ).autocomplete({
		source: function( request, response ) {
	        $.ajax({
	          url: contextPath + '/iccard/report/getSellers',
	          dataType: "json",
	          data: {
	            maxRows: 10,
	            keyword: request.term
	          },
	          success: function( data ) {
	        	sellerCode="";
	            response( $.map( data, function( item ) {
	              return {
	                label: item.value+','+item.label,
	                value: item.label
	              };
	            }));
	          }
	        });
	      },
	      minLength: 2,
	      select: function( event, ui ) {
		        sellerCode=ui.item.label;
	      },
	      open: function() {
	        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
	      },
	      close: function() {
	        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
	      }
	    });
});

function list(day) {
	searchDay = day;
	$("#data_list").datagrid({
		onLoadError : function() {
			uppAjaxError(data);
		},
		onLoadSuccess:function(data){
			$("#export_link").attr('href',contextPath+'/iccard/report/temp/'+data.fileName);
		},
		queryParams : {
			day : day
		},
		frozenColumns : [ [ {
			field : 'merchantName',
			title : '商户名称',
			width : 80
		}, {
			field : 'merchantCode',
			title : '商户编号',
			width : 80
		}, ] ],
		columns : [ [ {
			field : 'merchantDaliyEarningsDetailId',
			title : '',
			hidden : true
		}, {
			field : 'comboCardExpenseAmount',
			title : '套餐卡消费额'
		}, {
			field : 'comboCardHandleAmount',
			title : '套餐卡应付额'
		}, {
			field : 'comboCardExpectedEarnings',
			title : '套餐卡预期收益额'
		}, {
			field : 'rechargeableCardExpenseAmount',
			title : '充值卡消费额'
		}, {
			field : 'rechargeableCardHandleAmount',
			title : '充值卡应付额'
		}, {
			field : 'rechargeableCardExpectedEarnings',
			title : '充值卡预期收益额'
		}, {
			field : 'expenseTotalAmount',
			title : '消费总额'
		}, {
			field : 'handleTotalAmount',
			title : '应付总额'
		}, {
			field : 'expectedTotalEarnings',
			title : '预期收益总额'
		}, {
			field : 'daliyEarningsDate',
			title : '    日期        ',
			align : 'center',
			formatter : function(value, row, index) {
				var d =new Date(Number(value));
				return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			}
		} ] ],
		autoRowHeight : true,
		fitColumns : true,
		pagination : true,
		nowrap : false,
		singleSelect : true,
		rownumbers : true
	});

}

function doSearch(){
	$("#data_list").datagrid({
		onLoadError : function() {
			uppAjaxError(data);
		},
		onLoadSuccess:function(data){
			$("#export_link").attr('href',contextPath+'/iccard/report/temp/'+data.fileName);
		},
		queryParams : {
			day : searchDay,
			sellerCode : sellerCode
		},
		frozenColumns : [ [ {
			field : 'merchantName',
			title : '商户名称',
			width : 80
		}, {
			field : 'merchantCode',
			title : '商户编号',
			width : 80
		}, ] ],
		columns : [ [ {
			field : 'merchantDaliyEarningsDetailId',
			title : '',
			hidden : true
		}, {
			field : 'comboCardExpenseAmount',
			title : '套餐卡消费额'
		}, {
			field : 'comboCardHandleAmount',
			title : '套餐卡应付额'
		}, {
			field : 'comboCardExpectedEarnings',
			title : '套餐卡预期收益额'
		}, {
			field : 'rechargeableCardExpenseAmount',
			title : '充值卡消费额'
		}, {
			field : 'rechargeableCardHandleAmount',
			title : '充值卡应付额'
		}, {
			field : 'rechargeableCardExpectedEarnings',
			title : '充值卡预期收益额'
		}, {
			field : 'expenseTotalAmount',
			title : '消费总额'
		}, {
			field : 'handleTotalAmount',
			title : '应付总额'
		}, {
			field : 'expectedTotalEarnings',
			title : '预期收益总额'
		}, {
			field : 'daliyEarningsDate',
			title : '    日期        ',
			align : 'center',
			formatter : function(value, row, index) {
				var d =new Date(Number(value));
				return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			}
		} ] ],
		autoRowHeight : true,
		fitColumns : true,
		pagination : true,
		nowrap : false,
		singleSelect : true,
		rownumbers : true
	});
}